// filename: skia_gdi_bridge.h
// author: enic
// date: 2015-01-26

#pragma once

#include <windef.h>
#include "import_skia.h"

//void SkSetDIBitsToDevice(HDC hDestDC, int iDestX, int iDestY, int iDestWitdh, int iDestHeight,
//						 SkBitmap& bitmap, int iSrcX, int iSrcY, int iSrcWitdh, int iSrcHeight)
inline void SkSetDIBitsToDevice(HDC hDestDC, SkBitmap& bitmap)
{
	BITMAPINFO bmi;
	memset(&bmi, 0, sizeof(bmi));
	bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
	bmi.bmiHeader.biWidth       = bitmap.width();
	bmi.bmiHeader.biHeight      = -bitmap.height(); // top-down image
	bmi.bmiHeader.biPlanes      = 1;
	bmi.bmiHeader.biBitCount    = 32;
	bmi.bmiHeader.biCompression = BI_RGB;
	bmi.bmiHeader.biSizeImage   = 0;

	bitmap.lockPixels();
	int ret = SetDIBitsToDevice(hDestDC,
		0, 0,
		bitmap.width(), bitmap.height(), 
		0, 0,
		0, bitmap.height(),
		bitmap.getPixels(),
		&bmi,
		DIB_RGB_COLORS);

	(void)ret; // we're ignoring potential failures for now.

	bitmap.unlockPixels();
}

//void SkSetDIBitsToDevice(HDC hDestDC, int iDestX, int iDestY, int iDestWitdh, int iDestHeight,
//						 SkBitmap& bitmap, int iSrcX, int iSrcY, int iSrcWitdh, int iSrcHeight)
//{
//	BITMAPINFO bmi;
//	memset(&bmi, 0, sizeof(bmi));
//	bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
//	bmi.bmiHeader.biWidth       = bitmap.width();
//	bmi.bmiHeader.biHeight      = -bitmap.height(); // top-down image
//	bmi.bmiHeader.biPlanes      = 1;
//	bmi.bmiHeader.biBitCount    = 32;
//	bmi.bmiHeader.biCompression = BI_RGB;
//	bmi.bmiHeader.biSizeImage   = 0;
//
//	bitmap.lockPixels();
//	int ret = SetDIBitsToDevice(hDestDC,
//		iDestX, iDestY,
//		iDestWitdh, iDestHeight, 
//		0, 0,
//		0, bitmap.height(),
//		bitmap.getPixels(),
//		&bmi,
//		DIB_RGB_COLORS);
//
//	(void)ret; // we're ignoring potential failures for now.
//
//	bitmap.unlockPixels();
//}